<template>
  <el-container class="home-container">
    <el-header>
      <span>后台模板</span>
      <el-button type="info" @click="logout">Exit</el-button>
    </el-header>
    <el-container>
      <el-aside :width="isCollapse ? '64px' : '200px'">
        <div class="toggle-button" @click="toggleCollapse">|||</div>
        <el-menu
          background-color="#ADD8E6"
          active-text-color="#409EFF"
          unique-opened
          :collapse="isCollapse"
          router
          :collapse-transition="false"
        >
          <!-- 一级菜单 -->
          <el-menu-item
            :index="item.path"
            v-for="item in menuList"
            :key="item.id"
          >
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>{{ item.name }}</span>
            </template>
          </el-menu-item>
          <!-- <el-submenu 
          :index="item.path" 
          v-for="item in menuList" 
          :key="item.id">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>{{item.name}}{{item.path}}</span>
          </template>-->
          <!-- <el-menu-item-group>
              <template slot="title">分组1</template>
               二级菜单 
             
              <el-menu-item :index="subItem.path" v-for="subItem in item.children" :key="subItem.id">
                <i class="el-icon-menu"></i>
                <span>{{subItem.authName}}</span>
              </el-menu-item>
          </el-menu-item-group>-->
          <!-- </el-submenu> -->
        </el-menu>
      </el-aside>
      <el-main>
        <router-view />
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data() {
    return {
      menuList: [
        { id: 1, name: "用户管理", path: "/user" },
        { id: 2, name: "歌曲管理", path: "/song" },
        { id: 3, name: "评论管理", path: "/comment" },
        { id: 4, name: "歌单管理", path: "/collect" },
         { id: 5, name: "权限管理", path: "/collect" }
      ],
      isCollapse: false
    };
  },
  created() {
    //this.getMenuList();
  },
  methods: {
    logout() {
      window.sessionStorage.clear();
      this.$router.push("/login");
      this.$message.error("退出登录");
    },
    // getMenuList() {
    //   this.$http.get("getMenu")
    //   .then(response => {
    //     if(response.data.code == 0){
    //       this.$message.info("菜单获取成功");
    //       this.menuList = response.data.data
    //       console.log(this.menuList)
    //     }
    //     console.log(response.data);
    //   })
    //   .catch(error => {
    //     this.$message.error("菜单获取失败");
    //     console.log(error);
    //   });
    // },
    toggleCollapse() {
      this.isCollapse = !this.isCollapse;
    }
  }
};
</script>

<style scoped>
.el-header {
  background-color: lightblue;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #000;
  font-size: 20px;
}
.el-aside {
  background-color: lightblue;
}

.el-menu {
  border-right: none;
}
.el-main {
  background-color: #e8f2e8
}
.home-container {
  height: 100%;
}
.toggle-button {
  background-color: lightblue;
  font-size: 10px;
  line-height: 24px;
  color: #fff;
  text-align: center;
  letter-spacing: 0.2em;
  cursor: pointer;
}
</style>
